<template>
  <div class="header_container">
    <div class="container">
      <!-- logo   -->
      <div class="logo">
        <router-link key="collapse" class="sidebar-logo-link" to="/">
          <el-image :src="'https://rs.dance365.com/logo@3xrenew3.png'" :fit="'contain'"/>
        </router-link>
      </div>
      <!--  菜单  -->

      <el-menu
          :default-active="activeIndex"
          mode="horizontal"
          @select="(key)=>{router.push(key);}"
          class="menu"
      >
        <el-menu-item index="/recomend">资源</el-menu-item>
        <el-menu-item index="/course">课程</el-menu-item>
        <el-menu-item index="/practice">练习室</el-menu-item>
        <el-menu-item index="/communication">交流</el-menu-item>
        <el-menu-item index="/me">我的</el-menu-item>
      </el-menu>
      <!--  下载App 发布 登录  -->
      <div class=" download">
        <el-link :underline="false" class="download_icon">
          <el-icon>
            <Iphone/>
          </el-icon>
          下载APP
        </el-link>
        <el-dropdown>
          <el-button round class="publish">
            <el-icon>
              <Plus/>
            </el-icon>&nbsp;发布
          </el-button>
          <template #dropdown>
            <el-dropdown-menu placement="top">
              <el-dropdown-item>Action 1</el-dropdown-item>
              <el-dropdown-item>Action 2</el-dropdown-item>
              <el-dropdown-item>Action 3</el-dropdown-item>
              <el-dropdown-item disabled>Action 4</el-dropdown-item>
              <el-dropdown-item divided>Action 5</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
        <el-dropdown >
          <!-- src="https://joeschmoe.io/api/v1/random"  -->
          <el-avatar class="el-dropdown-link" >
            <img v-if="userInfoStore.token" src="/qq.png">
            <el-button v-else >
              <router-link to="/login">登录</router-link>
            </el-button>
          </el-avatar>
          <template #dropdown>
            <el-dropdown-menu placement="top">
              <el-dropdown-item v-if="userInfoStore.token" @click="logout">退出登录</el-dropdown-item>
<!--              <el-dropdown-item>Action 1</el-dropdown-item>-->
<!--              <el-dropdown-item>Action 2</el-dropdown-item>-->
<!--              <el-dropdown-item>Action 3</el-dropdown-item>-->
<!--              <el-dropdown-item disabled>Action 4</el-dropdown-item>-->
<!--              <el-dropdown-item divided>Action 5</el-dropdown-item>-->
            </el-dropdown-menu>
          </template>
        </el-dropdown>

      </div>
    </div>
  </div>


</template>

<script setup lang="ts">
import {ref} from "vue";
import { useUserInfoStore } from '@/stores/login';
import { useRoute, useRouter } from 'vue-router';
const userInfoStore = useUserInfoStore()
const router = useRouter()
const activeIndex = ref('/')

const logout = async () => {
  await userInfoStore.reset()
  router.push('/login')
}
</script>

<style scoped lang="less">
.el-menu {
  margin: 0;
}

.el-image {
  width: 128px;
  height: 30px;
  margin-top: 15px;
  margin-right: 5px;
  float: right;
}

.el-dropdown-link {
  width: 30px;
  height: 30px;
  cursor: pointer;
}

.el-menu--horizontal {
  border-bottom: none;

  & > .el-menu-item.is-active {
    border-bottom: none;
    color: #f93684 !important;
  }
}

.el-menu--horizontal .el-menu-item:not(.is-disabled):focus, .el-menu--horizontal .el-menu-item:not(.is-disabled):hover {
  outline: 0;
  color: #f93684;
  background-color: transparent;
}

.el-menu--horizontal .el-menu-item {
  font-size: 18px;
  padding: 0 10px;
  color: #111;

  &:not(:first-child) {
    margin-left: 40px;
  }
}

.header_container {
  box-shadow: 4px 0 9px #c1c1c1;

  .container {
    width: 1200px;
    margin: 0 auto;
    // 清除浮动
    &:before, &:after {
      content: '';
      clear: both;
      display: block;
    }

    .logo {
      float: left;
      margin-right: 30px;
    }

    .menu {
      float: left;
    }

    .download {
      float: right;
      display: flex;
      align-items: center;
      height: 60px;

      .download_icon {
        font-weight: bold;
        font-size: 16px;
        color: #101010;
      }

      .publish {
        background-color: #f93684;
        color: white;
        margin: 0 28px 0 30px
      }
    }

  }

}

</style>
